//
//  YBNineTableViewCell.m
//  GoodBuy
//
//  Created by Cyber on 15/5/13.
//  Copyright (c) 2015年 GoodBuy. All rights reserved.
//

#import "YBNineTableViewCell.h"

@implementation YBNineTableViewCell

-(void)dealloc {
    [_titleLabel release];
    [_nowPrise release];
    [_pictureView release];
    [_dealLabel release];
    [_nineModel release];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews {
    //去掉点击效果
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    
    //设置图片
    self.pictureView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, [UIScreen mainScreen].bounds.size.width - self.pictureView.frame.origin.x*2, [UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2)];
    self.pictureView.image = [UIImage imageNamed:@"NinetoNineImage"];
    _pictureView.contentMode = 2;
    _pictureView.layer.masksToBounds = YES;
    _pictureView.layer.cornerRadius = 20;
    _pictureView.layer.frame = CGRectMake(5, 5, [UIScreen mainScreen].bounds.size.width - self.pictureView.frame.origin.x*2, [UIScreen mainScreen].bounds.size.height/3 - self.pictureView.frame.origin.y*2);
    
    [self.contentView addSubview:self.pictureView];
    [_pictureView release];
    
    //设置标题
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    _titleLabel.frame = CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/3/5);
    [self.contentView addSubview:_titleLabel];
    _titleLabel.text = @"";
//    _titleLabel.textColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1];
    _titleLabel.shadowColor = [UIColor blackColor];
    _titleLabel.shadowOffset = CGSizeMake(1, 1);
//    _titleLabel.backgroundColor = [UIColor cyanColor];
    _titleLabel.font = [UIFont systemFontOfSize:20];
    _titleLabel.textColor = [UIColor whiteColor];
    [_titleLabel release];
    
    
    //现在价钱
    self.nowPrise = [[UILabel alloc]initWithFrame:CGRectMake(_titleLabel.frame.origin.x, [UIScreen mainScreen].bounds.size.height/3/5*4, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/3/5)];
//    self.nowPrise.text = @"现价￥:9.8";
    self.nowPrise.font = [UIFont systemFontOfSize:22];
    _nowPrise.textColor = [UIColor colorWithRed:1 green:0.5 blue:0.5 alpha:1];
    _nowPrise.shadowColor = [UIColor redColor];
    _nowPrise.shadowOffset = CGSizeMake(0, 1);
    [self.contentView addSubview:_nowPrise];
    [_nowPrise release];
    
    //销量
    self.dealLabel = [[UILabel alloc]initWithFrame:CGRectMake(_titleLabel.frame.origin.x + [UIScreen mainScreen].bounds.size.width/3*2 - 20, _nowPrise.frame.origin.y, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height/3/5)];
//    _dealLabel.text = @"销量:9876";
    _dealLabel.font = [UIFont systemFontOfSize:22];
    _dealLabel.textColor = [UIColor colorWithRed:0.5 green:0.5 blue:1 alpha:1.0];
    _dealLabel.shadowColor = [UIColor blueColor];
    _dealLabel.shadowOffset = CGSizeMake(1, 1);
    [self.contentView addSubview:_dealLabel];
    [_dealLabel release];
    
}

- (void)setNineModel:(YBNineModel *)nineModel {
    NSURL *pictureUrl = [NSURL URLWithString:nineModel.pic_url];
    [_pictureView sd_setImageWithURL:pictureUrl placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    _titleLabel.text = nineModel.title;
    NSLog(@"%@",nineModel.title);
    if (nineModel.title == Nil) {
        _nowPrise.text = [NSString stringWithFormat:@""];
        _dealLabel.text = [NSString stringWithFormat:@""];
    }else{
        _nowPrise.text = [NSString stringWithFormat:@"现价￥:%.1f", nineModel.now_price];
        _dealLabel.text = [NSString stringWithFormat:@"销量:%@",nineModel.deal_num];
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
